﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleBaseAndThis
{
    /// <summary>
    /// this只是调用本身，但是这样是需要调用一次基类没有参的构造函数，所以会多显示一条“基类的无参数构造函数. value:0”。
    /// base是调用基类的构造函数。
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            FileStream fs = new FileStream(@"E:\Code.txt", FileMode.Create, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            //List<int> Numbers = Program.GetRandom(1000000000, 2147483640, 210);              
            List<int> Numbers = Program.GetRandom(100000, 1000000, 20000); 
            for (int i = 0; i < Numbers.Count; i++)
            {
                Console.WriteLine("160927" + Numbers[i]);
                sw.WriteLine("160927" + Numbers[i]);
            }
            sw.Close();
            Console.WriteLine("写入文件完成");
            Console.ReadLine();
        }

        ///<summary>   
        ///返回一组唯一不重复的随机数   
        ///</summary>   
        ///<param name="minValue">最小值</param>   
        ///<param name="maxValue">最大值</param>   
        ///<returns>返回一组唯一不重复的随机数</returns>   
        public static List<int> GetRandom(int minValue, int maxValue, int count)
        {
            List<int> Numbers = new List<int>();
            //使用Guid.NewGuid().GetHashCode()作为种子，可以确保Random在极短时间产生的随机数尽可能做到不重复   
            Random rand = new Random(Guid.NewGuid().GetHashCode());
            Console.WriteLine("GUID:" + Guid.NewGuid().GetHashCode());
            int item;
            for (int i = minValue; i <= maxValue; i++)
            {
                item = rand.Next(minValue, maxValue + 1);
                //while (Numbers.IndexOf(item) != -1)
                //{
                    item = rand.Next(minValue, maxValue + 1);
                //}
                Numbers.Add(item);
                if (Numbers.Count >= count)
                    break;

            }

            return Numbers;
        }
        //static void Main(string[] args)
        //{
        //    SubCircle s1 = new SubCircle();
        //    SubCircle s2 = new SubCircle(1.1);
        //    SubCircle s3 = new SubCircle(1);
        //    SubCircle s4=new SubCircle("a");
        //    Console.ReadLine();
        //}
        public class BaseCircle
        {
            public BaseCircle()
            {
                Console.WriteLine(" 基类无参构造函数!!!");
            }
            public BaseCircle(double arg)
            {
                Console.WriteLine("基类有1个参数的构造函数!!");
            }
            public BaseCircle(int arg1,int arg2)
            {
                Console.WriteLine("基类有2个参数的构造函数!!");
            }
        }

        public class SubCircle : BaseCircle
        {
            public SubCircle()
                : base()
            {
                Console.WriteLine("子类构造函数没有参数,实际上调用基类无参构造函数 !!!");
            }

            public SubCircle(double a)
                : base(a)
            {
                Console.WriteLine("子类构造函数有参数, 实际上调用基类有参构造函数 !!!");
            }

            public SubCircle(int k)
                : this(1, 2)
            {
                Console.WriteLine("sub class with argument int k, actually call sub class constructor int i & j !!!");
            }

            public SubCircle(string k)
                : base(1, 2)
            {
                Console.WriteLine("sub class with argument string k, 调用基类的有参数构造函数 int i & j !!!"); 
            }
            public SubCircle(int i, int j)
            {
                Console.WriteLine("sub class with int i&j argument!!!!");
            }
        }

    }
}
